export default {
    namespaced: true,
    state: {
        // 显示提示框
        isShowToast: false,
        toastType: "success",
        toastMsg: "默认提示信息"
    },
    mutations: {
        // 修改提示框显示状态
        changeIsShowToast(state, payload) {
            state.isShowToast = payload.isShowToast;
            if (payload.isShowToast) {
                state.toastMsg = payload.msg;
                state.toastType = payload.type
            }

        }
    },
    // 执行异步代码在actions
    actions: {
        asyncIsShowToast({ commit }, payload) {
            // 调用mutations中的方法
            commit("changeIsShowToast", payload)
            // 添加定时器进行关闭
            setTimeout(() => {
                commit("changeIsShowToast", {
                    isShowToast: false
                })
            }, 2000)
        }
    }
}